//
//  DCBasicViewController.m
//  DCProject
//
//  Created by bigbing on 2019/4/1.
//  Copyright © 2019 bigbing. All rights reserved.
//

#import "DCBasicViewController.h"
#import "UINavigationController+FDFullscreenPopGesture.h"

@interface DCBasicViewController ()

@end

@implementation DCBasicViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self dc_navBarHidden:YES];
}


- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.edgesForExtendedLayout =  UIRectEdgeNone;
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    if (@available(ios 11.0,*)) {
        UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    [self settingBackButton];
}

#pragma mark - NavBar执行
-(void)settingBackButton{
    if (self.navigationController.viewControllers.count > 1) {
        UIBarButtonItem * left = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"navBack"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(popView)];
        self.navigationItem.leftBarButtonItem = left;
    }
}
-(void)settingRightBarButtonL:(id)obj withAction:(id)action{
    if (self.navigationController.viewControllers.count > 1) {
        UIBarButtonItem * left = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"navBack"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(popView)];
        self.navigationItem.rightBarButtonItem = left;
    }
}
#pragma -mark 自定义方法
-(void)popView{
    [self.view endEditing:YES];
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - 界面跳转 不需要判断是否登陆
- (void)dc_pushNextController:(id)controller
{
    [self.navigationController pushViewController:controller animated:YES];
}


#pragma mark - 界面跳转 需要判断是否登陆
- (void)dc_pushLoginNextController:(id)controller
{
//    if (![[DCLoginTool shareTool] dc_isLogin]) {
//        [[DCLoginTool shareTool] dc_pushLoginControllerSuccessBlock:^{
//            [self dc_pushNextController:controller];
//        }];
//        return;
//    }
    
    [self dc_pushNextController:controller];
}


/// 界面跳转h5界面
- (void)dc_pushWebControllerWithUrl:(NSString *)url
{
    DC_KeyWindow.userInteractionEnabled = NO;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        DC_KeyWindow.userInteractionEnabled = YES;
    });

//    WHBaseWebViewController *vc = [[WHBaseWebViewController alloc]initWithUrl: url];
//    [self dc_pushNextController:vc];
}


#pragma mark - 界面跳转h5界面
- (void)dc_pushWebController:(NSString *)path params:(NSString *)params
{
//    NSString * url = DC_H5BaseUrl;
//    if (path && [path length] > 0) {
//        url = [url stringByAppendingString:path];
//    }
//
//    if (params && [params length] > 0) {
//        url = [url stringByAppendingString:[NSString stringWithFormat:@"?%@",params]];
//    }
//
//    QYH5WebController * vc = [QYH5WebController new];
//    vc.path = url;
//    [self dc_pushNextController:vc];
}

#pragma mark - 界面跳转h5界面
- (void)dc_pushLoginWebController:(NSString *)path params:(NSString *)params
{
//    if (![[QYLoginTool shareTool] dc_isLogin]) {
//        [[QYLoginTool shareTool] dc_pushLoginController];
//        return;
//    }
    
    [self dc_pushWebController:path params:params];
}

#pragma mark - 添加自定义的返回事件
- (void)dc_addCustomBackEvent:(SEL)sel
{
    self.navigationItem.leftBarButtonItem = nil;
    
    //返回按钮自定义
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    negativeSpacer.width = -15;
    
    UIButton *button = [[UIButton alloc] init];
    [button setImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateHighlighted];
    button.frame = CGRectMake(0, 0, 38, 38);
    
    if (@available(ios 11.0,*)) {
        button.contentEdgeInsets = UIEdgeInsetsMake(0, -15,0, 0);
        button.imageEdgeInsets = UIEdgeInsetsMake(0, -10,0, 0);
    }
    
    [button addTarget:self action:sel forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    self.navigationItem.leftBarButtonItems = @[negativeSpacer, backButton];
}


#pragma mark - 设置导航栏是否透明
- (void)dc_navBarLucency:(BOOL)isLucency
{
    UIImage * image = isLucency ? [[UIImage alloc] init] : nil;
    
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}

#pragma mark - 设置导航栏标题字体 颜色
- (void)dc_navBarTitleWithFont:(UIFont *)font color:(UIColor *)color
{
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:color,NSFontAttributeName:font};
}

/// 设置导航栏标背景颜色
- (void)dc_navBarBackGroundcolor:(UIColor *)color
{
    [self.navigationController.navigationBar setBackgroundImage:[UIImage dc_initImageWithColor:color size:CGSizeMake(kScreenW, kNavBarHeight)] forBarMetrics:UIBarMetricsDefault];
}

#pragma mark - 设置消息栏样式
- (void)dc_statusBarStyle:(UIStatusBarStyle)style
{
    [UIApplication sharedApplication].statusBarStyle = style;
}

#pragma mark - 设置导航栏是否隐藏
- (void)dc_navBarHidden:(BOOL)isHidden
{
    [self.navigationController setNavigationBarHidden:isHidden animated:NO];
    
//    self.fd_prefersNavigationBarHidden = isHidden;
    
//    if (self.fd_prefersNavigationBarHidden) {
//        [self.navigationController setNavigationBarHidden:YES animated:NO];
//    } else {
//        [self.navigationController setNavigationBarHidden:NO animated:NO];
//    }
}

/// 设置侧滑是否禁用
- (void)dc_popBackDisabled:(BOOL)disabled
{
    self.fd_interactivePopDisabled = disabled;
}



@end
